<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>医生</title>
    <link rel="stylesheet" href="/css/hospital.css"/>
    <script src="/js/jquery-1.8.3.js"></script>
    <!--就诊人表单相关设置-->
</head>
<body>
<!--隐藏的就诊人表单-->

<!-- 点击按钮 -->

<!--  弹框的div -->
<div id="contes">
    <h1>填写就诊人挂号信息</h1>
    <label>
        <span>当前账号：</span>
        <input type="text" value="" name="" id="UserId" >
    </label>
    <label>
        <span>就诊人姓名：</span>
        <input type="text" value="" name="name" id="patientName" >
    </label>
    <label>
        <span>电话：</span>
        <input type="text" value="" name="phone" id="patientPhone">
    </label>
    <label>
        <span>性别：</span>
        <input type="text" value="" name="garden" id="patientGarden">
    </label>
    <label>
        <span>身份证号码：</span>
        <input type="text" value="" name="idCard" id="patientIdCard" >
    </label>
    <label>
        <span>患者出生日期：</span>
        <input type="date" value="" name="birthday" id="patientBirthday">
    </label>
    <label>
        <span>地址：</span>
        <input type="text" value="" name="address" id="patientAddress" >
    </label>
    <input type="button" value="提交" id="doRegister">
    <input type="button"  value="取消" id="quxiao">


</div>
<div id="all_light">
</div>
</body>


<!--展示医师信息-->
<div class="doctortime" th:each="first:${hisDoctors}">


    <table class="doctortimetable">
        <tr>
            <td class="doctorhead"><h1 id="doctorName">[[${first.doctorName}]] <span id="department">[[${first.department}]]</span><span
                    style="display:none" id="doctorId" >[[${first.id}]]</span></h1></td>
        </tr>
        <tr>
            <td class="doctorname"><h1>[[${first.title}]]</h1></td>
        </tr>

        <tr>
            <td>
                <p>
                    [[${first.remark}]]
                </p>
                <!--<input type="button" class="btn" onclick="add()" value="添加就诊人">-->
                <input  class="btn"  value="选择就诊日期">
            </td>
        </tr>
        <!--"<tr><td><a onclick='add()'>" + workTime + "剩余" + surplusNumber + "人</a></td></tr>";-->
        <tr th:id="${first.id}">
        </tr>
        <!--<tr>-->
        <!--    <td><a href="">2020-11-16(星期一) 上午 剩余3</a></td>-->
        <!--</tr>-->

    </table>

    <script>



        /*显示医师工作时间表及预约人数*/
        $(function () {
            let dId = [[${first.id}]];//医生Id
            $.ajax({
                url: "/hp/schedulingTable/doFindByDoctorId",//请求地址
                method: "post",//请求方式
                data: {id:dId},//请求参数
                success: function (result) {
                    /*获取医生工作表数据*/
                    for (let times of result.data) {
                        let timeId = times.id;
                        let doctorName = times.doctorName;
                        let doctorId = times.doctorId;
                        let workTime = times.workTime;
                        let surplusNumber = times.surplusNumber;
                        // let tr = "<tr><td><a onclick='add(this)'>" + workTime + "</a><span>"+surplusNumber+"人</span></td></tr>";
                        let tr = "<tr align='center'><td><a onclick='add("+doctorId+",\""+workTime+"\")'>" + workTime + "</a><span>"+surplusNumber+"人</span></td></tr>";
                        // let t = "<tr><td><a onclick='add(this)'>" + workTime + "</a></td></tr>";
                        // console.log(tr);
                        $("#"+dId).before(tr);

                    }
                },
                error: function () {
                    alert("请求失败");
                },
                cache: true,//默认条件下缓存开启 false
                async: true, //默认条件异步
            })
        })
    </script>
</div>

</body>
<script>

    /*提交预约相关信息*/
    $("#doRegister").click(function () {
        let Uphone = $("#UserId").val();//用户账号（电话号码）
        let name = $("#patientName").val();//就诊人姓名
        let phone = $("#patientPhone").val();//就诊人电话
        let garden = $("#patientGarden").val();//性别
        let idCard = $("#patientIdCard").val();//
        let birthday = $("#patientBirthday").val();//
        let address= $("#patientAddress").val();//
        // console.log(Uphone +","+name+","+phone+","+garden+","+idCard+","+birthday+","+address);

        var url = "/hp/hisPatient/doAddPatient"
        $.ajax({
            url: url,//提交注册用户信息地址
            method: "post",//请求方式
            data: {
                name:name,
                phone:phone,
                garden:garden,
                idCard:idCard,
                birthday:birthday,
                address:address
            },//请求参数
            success: function (result) {
                if(result.state==0){
                    alert(result.message);
                    return;
                }
                /*获取患者表数据*/
                for (let patient of result.data) {

                    let patientId =patient.id;

                    /*提交挂号预约信息信息*/
                    $(function () {
                        $.ajax({
                            url: "/hp/hisRegister/doAddRegister",//请求地址
                            method: "post",//请求方式
                            data: {
                                /*患者id*/
                                patientId:patientId,
                                /*患者姓名*/
                                patientName:name,
                                /*用户（id）|*/
                                userId:null,
                                /*用户名（电话号码）*/
                                userName:Uphone,
                                /*医生id*/
                                doctorId:a3,
                                /*医生姓名*/
                                doctorName:null,
                                /*医生科室*/
                                departmentName:null,
                                /*预约就诊时间*/
                                appointmentTime:a1
                            }
                            ,
                            success: function (result) {
                                /*获取医生工作表数据*/
                                alert("预约成功")
                                window.location.href="/hp/hisUser/main-1/"+a3+"/"+patientId;

                            },
                            error: function () {
                                alert("请求失败");
                            },
                            cache: true,//默认条件下缓存开启 false
                            async: true, //默认条件异步
                        })
                    })
                }
            },
            error: function () {
                alert("请求失败");
            },
            cache: true,//默认条件下缓存开启 false
            async: true, //默认条件异步
        })
    });

    /*点击事件触发隐藏的就诊人信息表单*/
    function add(doctorI,doTime) {
        /*预约医生信息*/
        window["a1"]=doTime;//医生工作时间
        window["a3"]=doctorI;//医生id
        console.log(a1);
        console.log(a3);

        document.getElementById('contes').style.display = 'block';
        document.getElementById('all_light').style.display = 'block';

    }
    $("#quxiao").click(function () {
        document.getElementById('contes').style.display = 'none';
        document.getElementById('all_light').style.display = 'none';
    })

</script>
</html>